package com.vshining.grame

import org.grails.databinding.BindingFormat

class Role {
    String id = UUID.randomUUID().toString()
    String name
    @BindingFormat('yyyy-MM-dd HH:mm:ss')
    Date dateCreated
    @BindingFormat('yyyy-MM-dd HH:mm:ss')
    Date lastUpdated

    static hasMany = [users: User, permissions: String]
    static belongsTo = User

    static constraints = {
        //字符、数字或下划线开头，点号只能分隔字符或数字，其他内容可由字符、数字、下划线、减号组成，但必须以字符、数字或下划线结束。
        id bindable: true, matches: /^[\w\d_]+(?:(?:[\w\d].[\w\d])?[\w\d_-]+[\w\d_])*/
        // \/:*?"<>|以及控制字符不能作为名称
        name nullable: false, blank: false, unique: true, matches: /[^\\\/:*?"<>|\x00-\x1F\x7F]+/
    }
    static mapping = {
        id generator: 'assigned'
    }
}
